

<template>
  <div class="resume_header">
    <span>公司信息审核</span>
  </div>
  <div class="resume_center">
    <el-table :data="filterTableData.slice((page - 1) * limit, page * limit)" style="width: 100%" height="520px"
      size="large" @filter-change="tablesort">
      <el-table-column label="提交人" prop="hrName" width="150px" sortable column-key="hrName" :filters="filterHRData" />
      <el-table-column label="提交人电话" prop="hrPhone" width="140px" />
      <el-table-column label="提交时间" prop="confirmTime" width="240px" sortable column-key="confirmTime"
        :filters="filterConfirmTimeData" />
      <el-table-column label="审核时间" prop="auditTime" width="240px" sortable column-key="auditTime"
        :filters="filterAduitTimeData" />
      <el-table-column label="审核状态" prop="auditState" width="140px" sortable column-key="auditState"
        :filters="filterAduitStateData">
        <template #default="scope">
          <el-tag :type="ElTagState(scope.row.auditState)">
            {{ scope.row.auditState }}
          </el-tag>

        </template></el-table-column>
      <el-table-column align="right" min-width="300px">
        <template #header>
          <el-input v-model="search" size="default" placeholder="搜索" />
        </template>
        <template #default="scope">
          <el-button size="default" type="primary" @click="handleShowJObInfo(scope.$index, scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <PreAuditEnterpriseDialog v-if="preAuditEInfoDialog" :closePreAuditEInfoDialog="closePreAuditEInfoDialog"
      :preAuditEInfoDialog="preAuditEInfoDialog" />

    <div class="pagination">
      <Pagination :page="page" :limit="limit" :handleSizeChange="handleSizeChange"
        :handleCurrentChange="handleCurrentChange" :filterTableData="filterTableData" :pagesizes="pagesizes" />
    </div>

  </div>
</template>
<script lang='ts' setup>
import { TableColumnCtx } from 'element-plus/es/components/table/src/table-column/defaults';
import { eGetAuditEnterprise, ePreAuditEnterprise } from "@/api/enterpriseApi"
import { computed, ref, onMounted, reactive, watch, onBeforeMount } from 'vue'
import { useStore } from "vuex"
import Pagination from "@/components/Pagination.vue"
import { data, elmessage, formatDate, ElTagState } from "@/hook/hook";
import { useRouter } from "vue-router"
import { ElMessageBox } from 'element-plus'

import PreAuditEnterpriseDialog from "@/components/PreAuditEnterpriseDialog.vue"
const store = useStore()
const router = useRouter()

// 表格数据定义
interface ES {
  auditId: string
  eId: string
  businessName: string
  hrId: string
  hrName: string
  hrPhone: string
  confirmTime: string
  auditTime: string
  auditState: string
  isAudit: string
}
const tableData: ES[] = reactive([])

const search = ref('')
const filterTableData = computed(() =>

  tableData.filter(
    (data, index) =>
      !search.value ||
      // 通过提交时间筛选
      data.businessName.toLowerCase().indexOf(search.value.toLowerCase()) !== -1
  )
)
// 定义筛选类型
interface filterType {
  text: string,
  value: string
}

var hrNameArr: any = reactive([])
var confirmTimeArr: any = reactive([])
var auditTimeArr: any = reactive([])
var auditStateArr: any = reactive([])

const tableData_1: ES[] = reactive([])

const setHRNameArr = (arr: any) => {
  hrNameArr = arr
}
const getHRNameArr = () => {
  return hrNameArr
}
const setConfirmTimeArr = (arr: any) => {
  confirmTimeArr = arr
}
const getConfirmTimeArr = () => {
  return confirmTimeArr
}
const setAuditTimeArr = (arr: any) => {
  auditTimeArr = arr
}
const getAuditTimeArr = () => {
  return auditTimeArr
}
const setAuditStateArr = (arr: any) => {
  auditStateArr = arr
}
const getAuditStateArr = () => {
  return auditStateArr
}

const tablesort = (filterArr: ES) => {
  // 清除原表格数据
  tableData.splice(0, tableData.length)
  if ((typeof (filterArr.hrName)) == "object") {
    setHRNameArr(filterArr.hrName)
  }
  if ((typeof (filterArr.confirmTime)) == "object") {
    setConfirmTimeArr(filterArr.confirmTime)
  }
  if ((typeof (filterArr.auditTime)) == "object") {
    setAuditTimeArr(filterArr.auditTime)
  }
  if ((typeof (filterArr.auditState)) == "object") {
    setAuditStateArr(filterArr.auditState)
  }

  const hrNameLength = getHRNameArr().length
  const confirmTimeLength = getConfirmTimeArr().length
  const auditTimeLength = getAuditTimeArr().length
  const auditStateLength = getAuditStateArr().length
  

  // 按筛选条件重新加入数据
  tableData_1.forEach((valu: any, index: any, arr_1: any) => {



    // 所有筛选重置，即最初排序
    if (hrNameLength == 0 && confirmTimeLength == 0 && auditTimeLength == 0 && auditStateLength == 0) {
      if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
        tableData.push(valu)
      }

    }

    // 只筛选提交人（招聘者HR）姓名
    else if (hrNameLength > 0 && confirmTimeLength == 0 && auditTimeLength == 0 && auditStateLength == 0) {

      if (getHRNameArr().includes(valu["hrName"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }
      }
    }
    // 只筛选提交时间
    else if (hrNameLength == 0 && confirmTimeLength > 0 && auditTimeLength == 0 && auditStateLength == 0) {
      if (getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }
      }
    }
    // 只筛选审核时间
    else if (hrNameLength == 0 && confirmTimeLength == 0 && auditTimeLength > 0 && auditStateLength == 0) {
      if (getAuditTimeArr().includes(valu["auditTime"].split(" ")[0])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }
      }
    }
    // 只筛选审核状态
    else if (hrNameLength == 0 && confirmTimeLength == 0 && auditTimeLength == 0 && auditStateLength > 0) {
      if (getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }
      }
    }
    // 筛选提交人（招聘者HR）姓名、提交时间
    else if (hrNameLength > 0 && confirmTimeLength > 0 && auditTimeLength == 0 && auditStateLength == 0) {
      if (getHRNameArr().includes(valu["hrName"]) && getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 筛选提交人（招聘者HR）姓名、审核时间
    else if (hrNameLength > 0 && confirmTimeLength == 0 && auditTimeLength > 0 && auditStateLength == 0) {
      if (getHRNameArr().includes(valu["hrName"]) && getAuditTimeArr().includes(valu["auditTime"].split(" ")[0])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 筛选提交人（招聘者HR）姓名、审核状态
    else if (hrNameLength > 0 && confirmTimeLength == 0 && auditTimeLength == 0 && auditStateLength > 0) {
      if (getHRNameArr().includes(valu["hrName"]) && getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 提交时间、审核时间
    else if (hrNameLength == 0 && confirmTimeLength > 0 && auditTimeLength > 0 && auditStateLength == 0) {
      if (getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0]) && getAuditTimeArr().includes(valu["auditTime"].split(" ")[0])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 提交时间、审核状态
    else if (hrNameLength == 0 && confirmTimeLength > 0 && auditTimeLength == 0 && auditStateLength > 0) {
      if (getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0]) && getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 审核时间、审核状态
    else if (hrNameLength == 0 && confirmTimeLength == 0 && auditTimeLength > 0 && auditStateLength > 0) {
      if (getAuditTimeArr().includes(valu["auditTime"].split(" ")[0]) && getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 筛选提交人（招聘者HR）姓名、提交时间、审核时间
    else if (hrNameLength > 0 && confirmTimeLength > 0 && auditTimeLength > 0 && auditStateLength == 0) {
      if (getHRNameArr().includes(valu["hrName"]) && getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0]) && getAuditTimeArr().includes(valu["auditTime"].split(" ")[0])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 筛选提交人（招聘者HR）姓名、审核时间、审核状态
    else if (hrNameLength > 0 && confirmTimeLength == 0 && auditTimeLength > 0 && auditStateLength > 0) {
      if (getHRNameArr().includes(valu["hrName"]) && getAuditTimeArr().includes(valu["auditTime"].split(" ")[0]) && getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 筛选提交人（招聘者HR）姓名、提交时间、审核状态
    else if (hrNameLength > 0 && confirmTimeLength > 0 && auditTimeLength == 0 && auditStateLength > 0) {
      if (getHRNameArr().includes(valu["hrName"]) && getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0]) && getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 提交时间、审核时间、审核状态
    else if (hrNameLength == 0 && confirmTimeLength > 0 && auditTimeLength > 0 && auditStateLength > 0) {
      if (getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0]) && getAuditTimeArr().includes(valu["confirmTime"].split(" ")[0]) && getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }
    // 提交人（招聘者HR）姓名、提交时间、审核时间、审核状态
    else if (hrNameLength > 0 && confirmTimeLength > 0 && auditTimeLength > 0 && auditStateLength > 0) {

      if (getHRNameArr().includes(valu["hrName"]) && getConfirmTimeArr().includes(valu["confirmTime"].split(" ")[0]) && getAuditTimeArr().includes(valu["auditTime"].split(" ")[0]) && getAuditStateArr().includes(valu["auditState"])) {
        if (tableData.findIndex((item: { auditId: string; }) => item.auditId == valu["auditId"]) == -1) {
          tableData.push(valu)
        }

      }
    }



  })



}


// HR姓名筛选排序
const filterHR = (
  value: string,
  row: ES,
  column: TableColumnCtx<ES>
) => {
  // const property = column['property']
  return row["hrName"] === value
}
const filterHRData: filterType[] = reactive([])

// 提交时间筛选排序
const filterConfirmTime = (
  value: string,
  row: ES,
  column: TableColumnCtx<ES>
) => {
  // const property = column['property']
  return row["confirmTime"].split(" ")[0] === value
}
const filterConfirmTimeData: filterType[] = reactive([])
// 审核时间筛选排序
const filterAduitTime = (
  value: string,
  row: ES,
  column: TableColumnCtx<ES>
) => {
  // const property = column['property']
  if (value != "null") {


    return row["auditTime"].split(" ")[0] === value
  } else {
    return row["auditTime"] === value
  }

}
const filterAduitTimeData: filterType[] = reactive([])

// 审核状态筛选排序
const filterAduitState = (
  value: string,
  row: ES,
  column: TableColumnCtx<ES>
) => {
  // const property = column['property']
  return row["auditState"] === value
}
const filterAduitStateData: filterType[] = reactive([])


// 分页器
const page = ref(1)
const pagesizes = ref([1, 2, 3, 4, 10, 20, 30, 40])
const limit = ref(10)

const handleSizeChange = (val: number) => {
  limit.value = val
  page.value = 1
}
const handleCurrentChange = (val: number) => {
  page.value = val
}


// 查看具体修改的内容
const preAuditEInfoDialog = ref(false)

const e = store.state.adminState.audite
const getPreAuditEnterpriseInfo = (auditId: string) => {
  const newData = {
    ...data(),
    auditId: auditId
  }
  ePreAuditEnterprise(newData).then((res: any) => {
    if (res.data["code"] == "200") {
      e.auditId = res.data.datas[0].auditId
      e.eId = res.data.datas[0].eId
      e.eContent = res.data.datas[0].eContent
      e.eSize = res.data.datas[0].eSize
      e.eNature = res.data.datas[0].eNature
      e.eIndustry = res.data.datas[0].eIndustry
      e.eAdvantage = res.data.datas[0].eAdvantage

      e.contactName = res.data.datas[0].contactName
      e.contactPhone = res.data.datas[0].contactPhone
      e.contactEmail = res.data.datas[0].contactEmail
      e.contactAddress = res.data.datas[0].contactAddress

      e.businessName = res.data.datas[0].businessName
      e.businessSetTime = res.data.datas[0].businessSetTime
      e.businessRegCapital = res.data.datas[0].businessRegCapital
      e.businessLegalRepresentative = res.data.datas[0].businessLegalRepresentative

      e.hrId = res.data.datas[0].hrId
      e.hrName = res.data.datas[0].hrName
      e.hrEmail = res.data.datas[0].hrEmail
      e.hrPhone = res.data.datas[0].hrPhone

      e.isAudit = res.data.datas[0].isAudit
      e.auditTime = res.data.datas[0].auditTime
      e.confirmTime = res.data.datas[0].confirmTime
      e.auditState = res.data.datas[0].auditState
      e.operationType = res.data.datas[0].operationType
      e.auditResultContent = res.data.datas[0].auditResultContent
      preAuditEInfoDialog.value = true
    } else if (res.data["code"] == "300") {
      elmessage(res.data["message"], res.data["type"])
      setTimeout(() => {
        router.replace("/login")
      }, 500);
      localStorage.clear()
    } else {
      console.log(res.data["message"]);

    }

  })
}
const handleShowJObInfo = (index: number, row: ES) => {
  getPreAuditEnterpriseInfo(row.auditId)
}

const closePreAuditEInfoDialog = () => {
  preAuditEInfoDialog.value = false
}


const init = () => {
  eGetAuditEnterprise(data()).then((res: any) => {
    if (res.data["code"] == "200") {
      res.data.datas.forEach((value: any, index: any, self: any) => {
        tableData.push(value)
        tableData_1.push(value)
      })
      res.data["hrname"].forEach((value: any, index: any, self: any) => {
        filterHRData.push(value)
      });
      res.data["confirmtime"].forEach((value: any, index: any, self: any) => {
        filterConfirmTimeData.push(value)
      });
      res.data["audittime"].forEach((value: any, index: any, self: any) => {
        filterAduitTimeData.push(value)
      });
      res.data["auditstate"].forEach((value: any, index: any, self: any) => {
        filterAduitStateData.push(value)
      });
      // console.log(tableData);

    } else if (res.data["code"] == "300") {
      elmessage(res.data["message"], res.data["type"])
      setTimeout(() => {
        router.replace("/login")
      }, 500);
      localStorage.clear()
    } else {
      console.log(res.data["message"]);

    }
  })
}

onBeforeMount(() => {
  init()
})


</script>
<style scoped>
.pagination {
  float: right;
  margin-right: 50px;
  /* right: 150px; */
}

.resume_center {
  font-family: '微软雅黑';
  height: 800px;
  background-color: #FFF;
}

.resume_header {
  background-color: rgb(215, 215, 215);
  height: 50px;
  display: flex;
  align-items: center;
  padding-left: 20px;
  justify-content: space-between;
}

a {
  text-decoration: none;
  color: #000;
}
</style>